import json,requests
def dingding(url,status=200,text=""):
    webhook = "https://oapi.dingtalk.com/robot/send?access_token=61ce20973cfdbc508d03e4c25a3085b770b09e044a2f5397438a1a91601c1531"
#构建请求头部
    header = {
        "Content-Type": "application/json",
        "Charset": "UTF-8"
    }
    if status!=200:
        message ={
        "msgtype": "markdown",
        # "keywords":"kmby",
        # "link": {
        # "text": "{}kmby".format(text),
        "markdown": {
                    "title": "{}发生异常！".format(url),
                    "text": "### {}无法正常访问_kmby\n".format(url)+
                     ">请求状态码：{}\n\n".format(status)+
                     ">请求结果：{}".format(text)
        }
        }
    else:
        message = {
            "msgtype": "link",
            "keywords": "kmby",
            "link": {
                "text": "{}已恢复正常！kmby".format(url),
                "title": "URL恢复正常",
                "picUrl": "http://kmzsccfile.kmzscc.com/upload/2020/success.jpg",
                "messageUrl": url
            }
        }
    message_json = json.dumps(message)
    info = requests.post(url=webhook,data=message_json,headers=header)
    return info.text
s=requests.get("http://www.baidu.com", timeout=5)
print(s.text)
print(dingding("www.baidu.com",300))